import 'package:flutter/material.dart';

class DrawerToScreenApp extends StatelessWidget {
  final String itemName ;
  DrawerToScreenApp({Key key,this.itemName}):super(key:key);

  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

  Drawer _buildDrawer(BuildContext context){

    return Drawer(
      child: ListView(
        children: <Widget>[
          DrawerHeader(
            child: Text('Drawer Header'),
            decoration: BoxDecoration(color: Colors.blueAccent),
          ),
          ListTile(
            title: Text('Item 1'),
            onTap: () {
              Navigator.pushNamed(context, '/SnackBarApp');

            }
          ),
          ListTile(
            title: Text(this.itemName),
            onTap: () {
              Navigator.pop(context);
            },
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Scaffold(
        key:_scaffoldKey,
        drawer: _buildDrawer(context),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            //显示抽屉
           // Navigator.push(context)
            //Scaffold.of(context).openDrawer();
            _scaffoldKey.currentState.openDrawer();
          },
          child: Icon(Icons.show_chart),
        ),
      ),
    );
  }
}
